<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>精选视频合集</title>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Arial, sans-serif;
        }

        /* 导航样式 */
        nav {
    background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
    padding: 1rem 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

nav::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.15),
        transparent
    );
    transition: 0.5s;
}

nav:hover::before {
    left: 100%;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

nav h1 {
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 2.2rem;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    letter-spacing: 1.5px;
    position: relative;
    padding-bottom: 0.5rem;
    transition: transform 0.3s ease;
}

nav h1::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 60px;
    height: 3px;
    background: #e74c3c;
    border-radius: 2px;
    transition: width 0.3s ease;
}

nav h1:hover {
    transform: translateY(-2px);
}

nav h1:hover::after {
    width: 100%;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        padding: 0 1.5rem;
    }
    
    nav h1 {
        font-size: 1.8rem;
        letter-spacing: 1px;
    }
}

/* 添加字体链接到<head> */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');

.clearboth {
    clear: both;
}

        /* 视频网格布局 */
        .video-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 每行4列 */
    gap: 2rem;
    margin-top: 2rem;
}

/* 视频卡片样式 */
.video-card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.video-card:hover {
    transform: translateY(-5px);
}

.thumbnail {
    width: 100%;
    height: 180px; /* 调整缩略图高度 */
    background: #ecf0f1;
    position: relative;
    cursor: pointer;
}

.play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}
.video-info {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

h3 {
    margin-bottom: 0.5rem;
    color: #2c3e50;
    font-size: 1.1rem; /* 调整标题字体大小 */
}

.video-description {
    color: #7f8c8d;
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1rem;
    flex-grow: 1; /* 描述部分自动填充剩余空间 */
}
.video-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: #95a5a6;
}
.like-btn {
    background: #f8f9fa;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.like-btn:hover {
    background: #e9ecef;
    transform: scale(1.05);
}

        /* 响应式设计 */
        @media (max-width: 1200px) {
    .video-grid {
        grid-template-columns: repeat(3, 1fr); /* 中等屏幕每行3列 */
    }
}
@media (max-width: 992px) {
    .video-grid {
        grid-template-columns: repeat(2, 1fr); /* 平板设备每行2列 */
    }
    
    .thumbnail {
        height: 160px;
    }
}
@media (max-width: 768px) {
    .video-grid {
        grid-template-columns: 1fr; /* 移动设备单列显示 */
        gap: 1.5rem;
    }
    
    .video-card {
        border-radius: 8px;
    }
    
    h3 {
        font-size: 1rem;
    }
    
    .play-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}
@media (max-width: 480px) {
    .thumbnail {
        height: 140px;
    }
    
    .video-info {
        padding: 1rem;
    }
    
    .video-description {
        font-size: 0.85rem;
    }
}

        /* 模态框样式 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.8);
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }

        .modal-content {
            width: 80%;
            max-width: 1000px;
            background: white;
            padding: 20px;
            border-radius: 10px;
        }
    </style>
</head>
<body>
    <nav>
        <div class="container">
            <h1>精选视频</h1>
            <!-- 后续可添加导航菜单 -->
        </div>
    </nav>

    <div class="container">
        <div class="video-grid">
            <!-- 视频1 -->
            <div class="video-card">
                <div class="thumbnail" onclick="openVideo('../video/video1.mp4')">
                    <div class="play-btn">▶</div>
                    <img src="../video/video_img1.png" alt="视频1封面" style="width:100%;height:100%;object-fit:cover;">
                </div>
                <div class="video-info">
                    <h3>深入理解机器学习</h3>
                    <p class="video-description">本视频讲解机器学习基本原理与实战应用。</p>
                    <div class="video-meta">
                        <span>时长：12:45</span>
                        <button class="like-btn">👍 326</button>
                    </div>
                </div>
            </div>

            <!-- 视频2 -->
            <div class="video-card">
                <div class="thumbnail" onclick="openVideo('../video/video2.mp4')">
                    <div class="play-btn">▶</div>
                    <img src="../video/video_img2.png" alt="视频2封面" style="width:100%;height:100%;object-fit:cover;">
                </div>
                <div class="video-info">
                    <h3>Web开发入门指南</h3>
                    <p class="video-description">从零开始学习现代Web开发技术栈。</p>
                    <div class="video-meta">
                        <span>时长：18:20</span>
                        <button class="like-btn">👍 489</button>
                    </div>
                </div>
            </div>
            <!-- 视频3 -->
            <div class="video-card">
                <div class="thumbnail" onclick="openVideo('../video/video3.mp4')">
                    <div class="play-btn">▶</div>
                    <img src="../video/video_img3.png" alt="视频2封面" style="width:100%;height:100%;object-fit:cover;">
                </div>
                <div class="video-info">
                    <h3>Web开发入门指南</h3>
                    <p class="video-description">从零开始学习现代Web开发技术栈。</p>
                    <div class="video-meta">
                        <span>时长：18:20</span>
                        <button class="like-btn">👍 489</button>
                    </div>
                </div>
            </div>
            <!-- 视频4 -->
            <div class="video-card">
                <div class="thumbnail" onclick="openVideo('../video/video3.mp4')">
                    <div class="play-btn">▶</div>
                    <img src="../video/video_img3.png" alt="视频2封面" style="width:100%;height:100%;object-fit:cover;">
                </div>
                <div class="video-info">
                    <h3>Web开发入门指南</h3>
                    <p class="video-description">从零开始学习现代Web开发技术栈。</p>
                    <div class="video-meta">
                        <span>时长：18:20</span>
                        <button class="like-btn">👍 489</button>
                    </div>
                </div>
            </div>
            <!-- 视频5 -->
            <div class="video-card">
                <div class="thumbnail" onclick="openVideo('../video/video3.mp4')">
                    <div class="play-btn">▶</div>
                    <img src="../video/video_img3.png" alt="视频2封面" style="width:100%;height:100%;object-fit:cover;">
                </div>
                <div class="video-info">
                    <h3>Web开发入门指南</h3>
                    <p class="video-description">从零开始学习现代Web开发技术栈。</p>
                    <div class="video-meta">
                        <span>时长：18:20</span>
                        <button class="like-btn">👍 489</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 视频模态框 -->
    <div id="videoModal" class="modal">
        <div class="modal-content">
            <video id="videoPlayer" controls style="width:100%">
                您的浏览器不支持视频播放
            </video>
        </div>
    </div>

    <script>
        // 视频播放控制
        const modal = document.getElementById('videoModal');
        const videoPlayer = document.getElementById('videoPlayer');

        function openVideo(videoPath) {
        // 完全重置播放器
        videoPlayer.pause();
        videoPlayer.innerHTML = ""; // 清空所有子元素
        
        // 创建新的source元素
        const source = document.createElement('source');
        source.src = videoPath;
        source.type = 'video/mp4';
        
        videoPlayer.appendChild(source);
        
        // 强制重新加载媒体
        videoPlayer.load(); // 关键修复点
        
        modal.style.display = 'flex';
        
        // 添加静音自动播放
        videoPlayer.muted = true;
        const playPromise = videoPlayer.play();
        
        playPromise.then(_ => {
            videoPlayer.muted = false;
        }).catch(error => {
            console.error('播放失败:', error);
        });
    }


        // 点击模态框背景关闭
        modal.addEventListener('click', (e) => {
            if (e.target === modal) {
                videoPlayer.pause();
                modal.style.display = 'none';
            }
        });

        // 键盘ESC关闭
        document.addEventListener('keydown', (e) => {
            if (e.key === 'Escape') {
                videoPlayer.pause();
                modal.style.display = 'none';
            }
        });
    </script>
</body>
</html>